<?php
/**
 * Created by PhpStorm.
 * User: 10037
 * Date: 2022/6/12
 * Time: 16:20
 */

namespace app\admin\controller;


use app\admin\model\Essaytable;
use app\admin\model\logtable;
use app\admin\model\Message;

class Essay
{
    public function addEssay($title,$headImg,$table,$textInfo,$summary){
        $essay=new Essaytable();
        $result= $essay->addEssay($title,$headImg,$table,$textInfo,$summary);
        if($result){
            $log=new logtable();
            $log->addLog('您添加了文章!');
            return json([
                'status'=>200
            ]);
        }

        return json([
            'status'=>400
        ]);
    }

    public function selectEssay($page){
        $essay=new Essaytable();
        return $essay->selectEssay($page);
    }

    public function deleteEssay($id){
        $essay=new Essaytable();
        $result=$essay->deleteEssay($id);
        if($result){
            $log=new logtable();
            $log->addLog('您删除了文章!');
            return json([
                'status'=>200
            ]);
        }

        return json([
            'status'=>300
        ]);
    }

    public function selectIdEssay($id){
        $essay=new Essaytable();
        return $essay->selectIdEssay($id);
    }

    public function updateEssay($id,$title,$headImg,$table,$textInfo,$summary){
        $essay=new Essaytable();
        $result= $essay->updateEssay($id,$title,$headImg,$table,$textInfo,$summary);
        if($result){
            $log=new logtable();
            $log->addLog('您修改了文章!');
            return json([
                'status'=>200
            ]);
        }

        return json([
            'status'=>400
        ]);
    }

    public function selectTextEssay($text){
        $essay=new Essaytable();
        return $essay->selectTextEssay($text);
    }

    public function selectMessage(){
        $message=new Message();
        return $message->selectMessage();
    }
}